package dict

var keys []Key
var items map[string][]Item

func Reload() error {
	ks := make([]Key, 0)
	if err := x.Find(&ks); err != nil {
		return err
	}
	is := make([]Item, 0)
	if err := x.Find(&is); err != nil {
		return err
	}
	ism := make(map[string][]Item)
	for _, item := range is {
		if _, ok := ism[item.Key]; !ok {
			ism[item.Key] = make([]Item, 0)
		}
		ism[item.Key] = append(ism[item.Key], item)
	}

	// 更新到缓存
	keys = ks
	items = ism
	return nil
}